package com.chance.cc.crawler.development.bootstrap.dangdang;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

/**
 * @ClassName dangdang
 * @Description TODO
 * @Author songding
 * @Date 2021/10/14 9:56
 * @Version 1.0
 * 当当网关键词查询  采集一日最新评论
 **/
public class DangdangStart {
    private static final String domain = "dangdang";
    private static final String site = "article";

    private static Proxy proxy = new Proxy();
    static {
        //代理配置
        //HL89Q19E86E2987D
        //71F33D94CE5F7BF2
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }
    public static void main(String[] args) {
         gatherSeries();
    }
    public static void gatherSeries() {
        String url = "https://search.dangdang.com/";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(domain)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 * 10000, null))
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .proxy(proxy)
                .build();
        record.setNeedWashPage(true);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site);
        record.tagsCreator().bizTags().addDomain(domain);


        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/dangdang/keys?site=searchKw")
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                .build();


        DevCrawlerController.builder()
                .triggerInfo(domain, domain, System.currentTimeMillis(), domain)
                .crawlerThreadNum(1)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .requestRecord(record)
                .supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.dangdang")
                .start();
    }

}
